import { configureStore } from '@reduxjs/toolkit';
import { createStateSyncMiddleware, initStateWithPrevTab } from 'redux-state-sync';
import counterReducer from './counterSlice';

const store = configureStore({
  reducer: { counter: counterReducer },
  middleware: (getDefault) =>
    getDefault().concat(createStateSyncMiddleware()), // ← 自动 IPC 同步
  devTools: true,
});

initStateWithPrevTab(store); // ← 启动时把其他进程状态拉回当前窗口
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
export default store;